﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace YGLAB_SON.Models
{
    public class MyRepo
    {
        public YgContext conn = new YgContext();


    }

    public class TruncateAndSeedInitializer : IDatabaseInitializer<YgContext>
    {
        public void InitializeDatabase(YgContext ygconn)
        {
            truncateTables(ygconn);

         

            Science science1 = new Science { Name = "Bilim Dalı 1" };
            Science science2 = new Science { Name = "Bilim Dalı 2" };
            Science science3 = new Science { Name = "Bilim Dalı 3" };
            Science science4 = new Science { Name = "Bilim Dalı 4" };
            ygconn.Sciences.Add(science1);
            ygconn.Sciences.Add(science2);
            ygconn.Sciences.Add(science3);
            ygconn.Sciences.Add(science4);

            Subject subject1 = new Subject { Name = "Araştırma Konusu 1" };
            Subject subject2 = new Subject { Name = "Araştırma Konusu 2" };
            Subject subject3 = new Subject { Name = "Araştırma Konusu 3" };
            Subject subject4 = new Subject { Name = "Araştırma Konusu 4" };
            Subject subject5 = new Subject { Name = "Araştırma Konusu 5" };
            Subject subject6 = new Subject { Name = "Araştırma Konusu 6" };
            ygconn.Subjects.Add(subject1);
            ygconn.Subjects.Add(subject2);
            ygconn.Subjects.Add(subject3);
            ygconn.Subjects.Add(subject4);
            ygconn.Subjects.Add(subject5);
            ygconn.Subjects.Add(subject6);

            Journal journal1 = new Journal { Name = "dergi 1", PathName = "dergi-1" };
            Journal journal2 = new Journal { Name = "dergi 2", PathName = "dergi-2" };
            ygconn.Journals.Add(journal1);
            ygconn.Journals.Add(journal2);
            ygconn.SaveChanges();

            // burda notification kısmını da ekleyeceğiz. 
            //InvitationToEditor InvEditor1 = new InvitationToEditor { Email = "user1@demir.com", Journal = journal1, Actepted = 0, LastAcceptTime = DateTime.Now + 1.Weeks() };


        }

        private void truncateTables(YgContext context)
        {
            context.Database.ExecuteSqlCommand("USE odev EXEC sp_MSforeachtable 'DELETE FROM ?'");
            context.SaveChanges();
        }
    }
}